interface Mediator{
    void Send(String message, Colleague colleague);
}
abstract class Colleague{
    protected Mediator mediator;
    public abstract void Accept(String message);
    public Colleague(Mediator mediator) {
        this.mediator = mediator;
    }
    public void Send(String message){
        mediator.Send(message,this);
    }
}
class ConcreteMediator implements Mediator{
    private Colleague colleague1;
    private Colleague colleague2;

    public void setColleague(Colleague colleague1,Colleague colleague2) {
        this.colleague1 = colleague1;
        this.colleague2 = colleague2;
    }

    @Override
    public void Send(String message, Colleague colleague) {
        if (colleague==this.colleague1){
            this.colleague2.Accept(message);
        }else {
            this.colleague1.Accept(message);
        }
    }
}
class ConcreteColleague1 extends Colleague{
    public ConcreteColleague1(Mediator mediator) {
        super(mediator);
    }
    public void Accept(String message){
        System.out.println("同事2对同事1说："+message);
    }
}
class ConcreteColleague2 extends Colleague{
    public ConcreteColleague2(Mediator mediator) {
        super(mediator);
    }
    public void Accept(String message){
        System.out.println("同事1对同事2说："+message);
    }
}
public class Test {
    public static void main(String[] args) {
        ConcreteMediator m=new ConcreteMediator();
        Colleague c1=new ConcreteColleague1(m);
        Colleague c2=new ConcreteColleague2(m);
        m.setColleague(c1,c2);
        c1.Send("吃饭了吗");
        c2.Send("刚吃了");
    }
}
